package com.elvin.zoe.pojo;

import java.util.ArrayList;
import java.util.List;

public class Conversation {

    private String with;
    private List<Message> messages = new ArrayList<Message>();

    public Conversation() {
        super();
    }

    public Conversation(String with, List<Message> messages) {
        super();
        this.with = with;
        this.messages = messages;
    }

    public Conversation merge(Conversation conversation) {
        if (conversation == null)
            return this;
        if (conversation.with == null)
            return this;
        
        if (this.with == null)
            this.with = conversation.with;
        
        if (!conversation.with.equals(with))
            return this;

        if (conversation.messages != null)
            messages.addAll(conversation.messages);
        
        return this;
    }

    public String getWith() {
        return with;
    }

    public void setWith(String with) {
        this.with = with;
    }

    public List<Message> getMessages() {
        return messages;
    }

    public void setMessages(List<Message> messages) {
        this.messages = messages;
    }

}
